/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pio.action.administrador.preinscripcion;

import DBMS.DataBaseManager;
import clases.CriterioTest;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

/**
 *
 * @author charles
 */
public class ModificarCriterio extends DispatchAction {

    private final static String SUCCESS = "success";
    private final static String FAILURE = "failure";

    public ActionForward populate(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        DataBaseManager dbms = DataBaseManager.getInstance();
        ArrayList <CriterioTest> ct = dbms.consultarCriterioTest(new CriterioTest());
        CriterioTest criterio = (CriterioTest) form;
        criterio.cloneWith(ct.get(0));
        return mapping.findForward(SUCCESS);
    }

    public ActionForward update(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        DataBaseManager dbms = DataBaseManager.getInstance();
        CriterioTest criterio = (CriterioTest) form;
        if (dbms.modificarCriterioTest(criterio)) {
             criterio.setMensaje("Criterio(s) modificado(s) exitosamente.");
            return mapping.findForward(SUCCESS);
        }else {
             criterio.setMensaje("No se pudo modificar algun criterio. ");
            return mapping.findForward(FAILURE);
        }
    }
}
